<template>
  <div class="box">
    <img style="width: 100%" src="../../assets/images/登录头像.png" alt="" />
    <div class="bdyz">
      <van-form>
        <van-cell-group inset>
          <van-field v-model="sms" center clearable placeholder="请输入邮箱">
            <template #button>
              <van-button size="small" type="primary">发送验证码</van-button>
            </template>
          </van-field>
          <van-field v-model="username" placeholder="请输入用户名" />
          <van-field
            v-model="password"
            type="password"
            name="密码"
            placeholder="请输入密码"
            :rules="[{ required: true, message: '请填写密码' }]"
          />
          <van-field v-model="value" placeholder="请再次确认密码" />
          <van-field v-model="sms" center clearable placeholder="请输入邀请码"> </van-field>
        </van-cell-group>
        <div style="margin: 16px">
          <van-button block type="primary" @click="goZegister"> 注册 </van-button>
        </div>
      </van-form>
    </div>
  </div>
</template>

<script>
import axios from 'axios'
import { message } from 'ant-design-vue'
export default {
  data() {
    return {
      username: '',
      password: ''
      // 其他数据...
    }
  },
  methods: {
    goZegister() {
      axios
        .post('http://localhost:3001/api/register', {
          username: this.username,
          password: this.password
        })
        .then((response) => {
          console.log('注册成功', response)
          // 这里可以添加其他逻辑，比如跳转到登录页面
          message.success('注册成功！')
          // 设置2秒后跳转
          setTimeout(() => {
            this.$router.push('/login') // 跳到登录
          }, 2000)
        })
        .catch((error) => {
          console.error('注册失败', error)
        })
    }
  }
}
</script>
<style>
.box {
  background-color: #3087ea;
}

.bdyz {
  width: 300px;
  height: 50%;
  margin-left: 37px;
  background-color: white;
  display: flex;
  align-items: center;
  justify-content: center;
}
.wjzc {
  width: 300px;
  height: 22px;
  font-size: 12px;
  /* background-color: azure; */
  margin: 10px 5px 10px 35px;
  color: white;
}
</style>
